from base.baseapi import BaseApi
from until.wework import WeWork

class Group(BaseApi):



    def __init__(self):
        self.token = WeWork().get_token('TYw5l5qSkfKTfPZY-EMeD7DPq3141OLDUJnQVBC6T3g')


    def create_section(self, id, name, parentid):
        data = {
            "method": "post",
            "url": "https://qyapi.weixin.qq.com/cgi-bin/department/create",
            "params": {
                "access_token": self.token
            },
            "json": {
                "id": id,
                "name": name,
                "parentid": parentid,

            }
        }
        return self.send(data)



# """
#     从2022年8月15日10点开始，“企业管理后台 - 管理工具 - 通讯录同步”的新增IP将不能再调用此接口，企业可通过「获取部门ID列表」接口获取部门ID列表。查看调整详情。
# """



    # 注意要传入的是父级部门的id来查询旗下的子部门id
    def find_section(self, id):
        data = {
            "method": "get",
            "url": "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist",
            "params": {
                "access_token": self.token
            },
            "json": {
                "id": id

        }}
        return self.send(data)


    def update_section(self, id, name, parentid):
        data = {
            "method": "post",
            "url": "https://qyapi.weixin.qq.com/cgi-bin/department/update",
            "params": {
                "access_token": self.token
            },
            "json": {
                "id": id,
                "name": name,
                "parentid": parentid
            }

        }

        return self.send(data)



    # delete部位无权限调用
    def delete_section(self, id):
        data = {
            "method": "get",
            "url": "https://qyapi.weixin.qq.com/cgi-bin/department/delete",
            "params": {
                "access_token": self.token
            },
            "json": {
                "id": id
            }
        }
        return self.send(data)









